package com.ruoyi.system.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.BuildingInfoMapper;
import com.ruoyi.system.domain.BuildingInfo;
import com.ruoyi.system.service.IBuildingInfoService;

/**
 * 楼宇信息Service业务层处理
 */
@Service
public class BuildingInfoServiceImpl implements IBuildingInfoService {
    @Autowired
    private BuildingInfoMapper buildingInfoMapper;

    /**
     * 查询楼宇信息
     * 
     * @param id 楼宇ID
     * @return 楼宇信息
     */
    @Override
    public BuildingInfo selectBuildingInfoById(Long id) {
        return buildingInfoMapper.selectBuildingInfoById(id);
    }

    /**
     * 查询楼宇信息列表
     * 
     * @param buildingInfo 楼宇信息
     * @return 楼宇信息
     */
    @Override
    public List<BuildingInfo> selectBuildingInfoList(BuildingInfo buildingInfo) {
        return buildingInfoMapper.selectBuildingInfoList(buildingInfo);
    }

    /**
     * 新增楼宇信息
     * 
     * @param buildingInfo 楼宇信息
     * @return 结果
     */
    @Override
    public int insertBuildingInfo(BuildingInfo buildingInfo) {
        // 生成楼宇编码
        String maxCode = buildingInfoMapper.getMaxBuildingCode();
        String newCode;
        if (maxCode == null) {
            newCode = "BLD0001";
        } else {
            int num = Integer.parseInt(maxCode.substring(3)) + 1;
            newCode = String.format("BLD%04d", num);
        }
        buildingInfo.setBuildingCode(newCode);
        return buildingInfoMapper.insertBuildingInfo(buildingInfo);
    }

    /**
     * 修改楼宇信息
     * 
     * @param buildingInfo 楼宇信息
     * @return 结果
     */
    @Override
    public int updateBuildingInfo(BuildingInfo buildingInfo) {
        return buildingInfoMapper.updateBuildingInfo(buildingInfo);
    }

    /**
     * 批量删除楼宇信息
     * 
     * @param ids 需要删除的楼宇ID
     * @return 结果
     */
    @Override
    public int deleteBuildingInfoByIds(Long[] ids) {
        return buildingInfoMapper.deleteBuildingInfoByIds(ids);
    }

    /**
     * 删除楼宇信息信息
     * 
     * @param id 楼宇ID
     * @return 结果
     */
    @Override
    public int deleteBuildingInfoById(Long id) {
        return buildingInfoMapper.deleteBuildingInfoById(id);
    }
} 